package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.MouldBoardMsg;
import cn.stylefeng.guns.sys.modular.system.entity.Project;
import cn.stylefeng.guns.sys.modular.system.model.params.ProjectParam;
import cn.stylefeng.guns.sys.modular.system.service.ProjectService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.alibaba.fastjson.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * 控制器
 *
 * @author jiangge
 * @Date 2020-09-10 21:46:43
 */
@Controller
@RequestMapping("/project")
public class ProjectController extends BaseController {

    private String PREFIX = "/modular/system/project/";

    @Autowired
    private ProjectService projectService;

    /**
     * 跳转到主页面
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "project.html";
    }

    /**
     * 编辑页面
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "project_edit.html";
    }

    /**
     * 填表页面(商务)
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/things")
    public String things(Integer id, ModelMap map) {
        map.put("id", id);
        map.put("list", selectMsgList(id, 36));
        return PREFIX + "project_things.html";
    }

    /**
     * 填表页面（工程）
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/projectTerm")
    public String projectTerm(Integer id, ModelMap map) {
        map.put("id", id);
        map.put("list", selectMsgList(id, 38));
        return PREFIX + "project_Term.html";
    }

    /**
     * 填表页面（网上建店）
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/internetStore")
    public String internetStore(Integer id, ModelMap map) {
        map.put("id", id);
        map.put("list", selectMsgList(id, 34));
        return PREFIX + "project_internetStore.html";
    }

    /**
     * 填表页面（线上套餐）
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/surfMeal")
    public String surfMeal(Integer id, ModelMap map) {
        map.put("id", id);
        map.put("list", selectMsgList(id, 35));
        return PREFIX + "project_surfMeal.html";
    }

    /**
     * 填表页面（排队机）
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/queuing")
    public String queuing(Integer id, ModelMap map) {
        map.put("id", id);
        map.put("list", selectMsgList(id, 37));
        return PREFIX + "project_queuing.html";
    }

    /**
     * 填表页面（现场踏勘）
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/premises")
    public String premises(Integer id, ModelMap map) {
        map.put("id", id);
        map.put("list", selectMsgList(id, 39));
        return PREFIX + "project_premises.html";
    }

    /**
     * 新增工程
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ProjectParam projectParam) {
        this.projectService.add(projectParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ProjectParam projectParam) {
        this.projectService.update(projectParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ProjectParam projectParam) {
        this.projectService.removeById(projectParam.getId());
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ProjectParam projectParam) {
        Project detail = this.projectService.getById(projectParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ProjectParam projectParam) {
        return this.projectService.findPageBySpec(projectParam);
    }

    /**
     * 跳到添加 工程/商务页面
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/jump")
    public String jump(String typeCode) {
        if ("GC_COND".equals(typeCode)) {
            return PREFIX + "project_gctj.html";
        } else if ("BUSY_COND".equals(typeCode)) {
            return PREFIX + "project_swtj.html";
        }
        return "";
    }

    /**
     * 工程条件数据保存
     *
     * @param
     * @return
     * @author gyz
     * @date 2020/9/18 16:39:01
     */
    @RequestMapping("/saveGctj")
    public void saveGctj() {

    }

    /**
     * 工程营运经理保存
     *
     * @param
     * @return
     * @author gyz
     * @date 2020/9/18 16:39:01
     */
    @RequestMapping("/saveGcyyjl")
    @ResponseBody
    public ResponseData saveGcyyjl(ProjectParam record) {
        projectService.saveGcyyjl(record);
        return ResponseData.success();
    }

    /**
     * 工程督导保存
     *
     * @param
     * @return
     * @author gyz
     * @date 2020/9/18 16:39:01
     */
    @RequestMapping("/saveGcDd")
    @ResponseBody
    public ResponseData saveGcDd(ProjectParam record) {
        projectService.saveGcDd(record);
        return ResponseData.success();
    }

    /**
     * 查询微信推送督导及营运经理
     *
     * @param proid
     * @return
     */
    @GetMapping("selectDd")
    public ResponseData selectDd(Integer proid) {
        projectService.selectDd(proid);
        return ResponseData.success();
    }

    /**
     * 查询督导列表
     *
     * @return
     */
    @RequestMapping(value = "/selectDdList")
    @ResponseBody
    public List<Map> selectDdList() {
        return projectService.selectDdList();
    }

    /**
     * 查询营运经理列表
     *
     * @return
     */
    @RequestMapping(value = "/selectYyjlList")
    @ResponseBody
    public List<Map> selectYyjlList() {
        return projectService.selectYyjlList();
    }

    /**
     * 查询需填表格列表
     */
    public String selectMsgList(Integer proId, Integer mouldId) {
        ArrayList<MouldBoardMsg> taskStatuses = (ArrayList) projectService.selectMsgList(proId, mouldId);
        String listJson = JSONArray.toJSONString(new ArrayList[]{taskStatuses});
        return listJson;
    }

}


